home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Libraries / glut / glut_cindex.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.2 KB  |  105 lines  |  [TEXT/CWIE]

  1. /* Copyright (c) Mark J. Kilgard, 1994, 1996. */
  2.  
  3. /* This program is freely distributable without licensing fees 
  4.    and is provided without guarantee or warrantee expressed or 
  5.    implied. This program is -not- in the public domain. */
  6.  
  7. #include <stdlib.h>
  8. #include "gl.h"
  9. #include "agl.h"
  10. #include "glut.h"
  11. #include "glutint.h"
  12.  
  13. GLUTcolormap *__glutColormapList = NULL;
  14.  
  15. extern GLUTwindow *__glutCurrentWindow;
  16. extern GLUTwindow **__glutWindowList;
  17.  
  18. #define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
  19.  
  20. void glutSetColor(int ndx, GLfloat red, GLfloat green, GLfloat blue)
  21. {
  22.     GLint tab[4];
  23.     
  24.     if(!__glutCurrentWindow || !__glutCurrentWindow->win)
  25.     {
  26.         __glutWarning("glutSetColor: no active window");
  27.         return;
  28.     }
  29.     
  30.     if(ndx < 0 || ndx > 255) return;
  31.     
  32.     tab[0] = ndx;
  33.     tab[1] = (GLushort) (CLAMP(red)   * 65535.0f);
  34.     tab[2] = (GLushort) (CLAMP(green) * 65535.0f);
  35.     tab[3] = (GLushort) (CLAMP(blue)  * 65535.0f);
  36.     
  37.     aglSetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
  38. }
  39.  
  40. GLfloat glutGetColor(int ndx, int component)
  41. {
  42.     GLint tab[4];
  43.     GLfloat color;
  44.     
  45.     if(!__glutCurrentWindow || !__glutCurrentWindow->win)
  46.     {
  47.         __glutWarning("glutGetColor: no active window");
  48.         return 0.0;
  49.     }
  50.     
  51.     if(ndx < 0 || ndx > 255) return 0.0;
  52.     
  53.     tab[0] = ndx;
  54.     
  55.     aglGetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
  56.     
  57.     switch(component)
  58.     {
  59.         case 0:
  60.             color = (GLfloat) tab[1] / 65535.0f;
  61.         break;
  62.         case 1:
  63.             color = (GLfloat) tab[2] / 65535.0f;
  64.         break;
  65.         default: /* case 2: */
  66.             color = (GLfloat) tab[3] / 65535.0f;
  67.         break;
  68.     }
  69.     
  70.     return color;
  71. }
  72.  
  73. void glutCopyColormap(int winnum)
  74. {
  75.     GLint tab[4], i;
  76.     GLUTwindow *dst_win;
  77.     
  78.     if(!__glutCurrentWindow || !__glutCurrentWindow->win)
  79.     {
  80.         __glutWarning("glutCopyColormap: no active window");
  81.         return;
  82.     }
  83.     
  84.     if(winnum < 1 || winnum > __glutWindowListSize)
  85.     {
  86.         __glutWarning("glutCopyColormap attempted on bogus window.");
  87.         return;
  88.     }
  89.     
  90.     dst_win = __glutWindowList[winnum - 1];
  91.     if(!dst_win)
  92.     {
  93.         __glutWarning("glutCopyColormap attempted on bogus window.");
  94.         return;
  95.     }
  96.     
  97.     for(i = 0; i < 256; i++)
  98.     {
  99.         tab[i] = i;
  100.         
  101.         aglGetInteger(__glutCurrentWindow->ctx, AGL_COLORMAP_ENTRY, tab);
  102.         aglSetInteger(dst_win->ctx, AGL_COLORMAP_ENTRY, tab);
  103.     }
  104. }
  105.